package org.zsqx.tools;

import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;

import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.apache.axis.encoding.ser.BeanDeserializer;
import org.apache.axis.encoding.ser.BeanDeserializerFactory;
import org.apache.axis.encoding.ser.BeanSerializer;
import org.apache.axis.encoding.ser.BeanSerializerFactory;
import org.codehaus.xfire.client.Client;
import org.zsqx.bean.Admin;

import cDao.CdaoFactory;
import cDao.RealDao;

public class TestNetService {

	private static String url = "http://202.105.179.68:8081/Service1.asmx";
	private static String namespace="http://sini.com/";
	private static String hello_method="HelloWorld1";
	private static String pdm_method="PDM1";
	
	public static String getTestForHelloworld(String name) {
		String result = "";
		try {
			Service service = new Service();
			Call call = (Call) service.createCall();
			call.setOperationName(new QName(namespace, hello_method));
			call.addParameter(new QName(namespace, "a"),
					XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
			call.setSOAPActionURI(namespace+hello_method);
			call.setUseSOAPAction(true);
			call.setReturnType(XMLType.XSD_STRING);
			call.setTargetEndpointAddress(new URL(url));
			result = (String) call.invoke(new Object[] { name });
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public static PDMRequestInfo getTestForPDM(PDMRequestInfo pdm) {
		PDMRequestInfo result = new PDMRequestInfo();
		try {
			Service service = new Service();
			Call call = (Call) service.createCall();
			QName qn = new QName("PDMRequestInfo");
			call.registerTypeMapping(PDMRequestInfo.class, qn,
					new BeanSerializerFactory(PDMRequestInfo.class, qn),
					new BeanDeserializerFactory(PDMRequestInfo.class, qn));
			call.setOperationName(new QName(namespace,pdm_method));
			call.setTargetEndpointAddress(new URL(url));
			call.setUseSOAPAction(true);
			call.addParameter(new QName(namespace, "PRQ"),XMLType.XSD_STRING, ParameterMode.IN);
			call.setSOAPActionURI("http://tempuri.org/EASReceive1");
			call.setReturnClass(PDMRequestInfo.class);
			call.setReturnType(XMLType.XSD_ANY);
			result = (PDMRequestInfo) call.invoke(new Object[] { pdm });
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public static String getTestForPDM2(String BizCode,String ActionCode,String TestFlag,String Priority,
			String SIAppID,String SIAppUserID,String TimeStamp,String TransID,String Version,String body) throws Exception{
		String result="";
		Service service = new Service();
		Call call = (Call) service.createCall();
		call.setOperationName(new QName(namespace, pdm_method));
		call.addParameter(new QName(namespace, "BizCode"),XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
		call.addParameter(new QName(namespace, "ActionCode"),XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
		call.addParameter(new QName(namespace, "TestFlag"),XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
		call.addParameter(new QName(namespace, "Priority"),XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
		call.addParameter(new QName(namespace, "SIAppID"),XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
		call.addParameter(new QName(namespace, "SIAppUserID"),XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
		call.addParameter(new QName(namespace, "TimeStamp"),XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
		call.addParameter(new QName(namespace, "TransID"),XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
		call.addParameter(new QName(namespace, "Version"),XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
		call.addParameter(new QName(namespace, "body"),XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
		call.setSOAPActionURI(namespace+pdm_method);
		call.setUseSOAPAction(true);
		call.setReturnType(XMLType.XSD_STRING);
		call.setTargetEndpointAddress(new URL(url));
		result= (String) call.invoke(new Object[] { BizCode,ActionCode ,TestFlag,Priority,SIAppID,SIAppUserID,TimeStamp,TransID,Version,body});
		return result;
	}
	
	public static void main(String[] args) throws Exception {
		RealDao rd=CdaoFactory.getRealDao();
		rd.find(new Admin());
	}
}
